import { defineStore } from 'pinia'
import type { ConsultIllness, PatientConsult } from '@/types/consult'
import { ref } from 'vue'
import type { ConsultType } from '@/enums'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // 1.问诊记录状态
    const consult = ref<PatientConsult>({})
    // 2.修改问诊类型函数
    const setType = (type: ConsultType) => {
      consult.value.type = type
    }
    // 3.修改极速问诊类型函数
    const setIllnessType = (type: 0 | 1) => {
      consult.value.illnessType = type
    }
    // 4.修改科室函数
    const setDep = (id: string) => (consult.value.depId = id)
    // 5.修改病情描述函数
    const setIllness = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }

    // 6.修改患者函数
    const setPatient = (id: string) => {
      consult.value.patientId = id
    }
    // 7.修改优惠券函数
    const setCouponId = (id: string) => {
      consult.value.couponId = id
    }

    // 8.清空记录
    const clear = () => (consult.value = {})
    return {
      consult,
      setType,
      setIllnessType,
      setDep,
      setIllness,
      setPatient,
      setCouponId,
      clear
    }
  },
  {
    persist: true // 数据持久化
  }
)
